package org.zjt.servletdemo.controller;

import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedWebappClassLoader;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ClassLoadTomcatController {

    @GetMapping("/tomcat/classload")
    public void classLoad() {
        ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
        TomcatEmbeddedWebappClassLoader embeddedWebappClassLoader = new TomcatEmbeddedWebappClassLoader(contextClassLoader.getParent());



        System.out.println(contextClassLoader.getClass());
        Thread.currentThread().setContextClassLoader(embeddedWebappClassLoader);


        ClassLoader classLoader = this.getClass().getClassLoader();
        while (classLoader != null){
            System.out.println(classLoader.getClass() +"    "+classLoader.getResource("") );
            classLoader = classLoader.getParent();
        }


    }
}
